﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using com.cruxomatic.items.navigationstrip;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        pnlNamedUrl.Visible = false;
        pnlTagUrl.Visible = false;
        
        
        //Uncomment for an Example for using in-buil ASP.Net Sitemap        
        VistaAddressBar1.CreateTreeFromSiteMap();
        pnlNamedUrl.Visible = true;


        //Uncomment for an Exmple for creating custom tree on the fly using "Name" and "Url"
        //VistaAddressBar1.Tree = CreateTreeNodesUsingNameAndUrl();


        //Uncomment for an Exmple for creating custom tree on the fly using "Name","Url" and "Tag"
        //VistaAddressBar1.Tree = CreateTreeNodesUsingNameURLAndTag();
    }

    protected void LinkButton_Clicked(object sender, LinkButtonEventArgs e)
    {
        string msg = string.Format("LinkButtonEvent Handled : Tree Node Name = <font style=\"FONT-WEIGHT: bold\">{0}</font>, Url = <font style=\"FONT-WEIGHT: bold\">{1}</font> and Tag = <font style=\"FONT-WEIGHT: bold\">{2}</font>",
            e.TreeNode.Name, e.TreeNode.Url, string.IsNullOrEmpty(e.TreeNode.Tag) ? "NULL" : e.TreeNode.Tag);
        lblText.Text = msg;

    }

    #region Create Tree Node using Name and Url

    private UrlTreeNode CreateTreeNodesUsingNameAndUrl()
    {
        UrlTreeNode tree = new UrlTreeNode("Home", "Home");

        UrlTreeNode folder1 = new UrlTreeNode("Folder1", "Folder1");
        UrlTreeNode folder2 = new UrlTreeNode("Folder2", "Folder2");
        UrlTreeNode folder3 = new UrlTreeNode("Folder3", "Folder3");
        UrlTreeNode folder4 = new UrlTreeNode("Folder4", "Folder4");
        UrlTreeNode folder10 = new UrlTreeNode("Folder10", "Folder10");
        UrlTreeNode folder11 = new UrlTreeNode("Folder11", "Folder11");
        UrlTreeNode folder12 = new UrlTreeNode("Folder12", "Folder12");
        UrlTreeNode folder20 = new UrlTreeNode("Folder20", "Folder20");

        folder1.AddChildNode(folder2);
        folder1.AddChildNode(folder3);

        folder11.AddChildNode(folder1);

        folder10.AddChildNode(folder11);
        folder10.AddChildNode(folder12);
        folder10.AddChildNode(folder1);

        folder2.AddChildNode(folder10);

        folder4.AddChildNode(folder2);
        folder4.AddChildNode(folder3);

        folder11.AddChildNode(folder4);

        folder20.AddChildNode(folder4);
        folder20.AddChildNode(folder11);
        folder20.AddChildNode(folder12);

        folder4.AddChildNode(folder10);

        tree.AddChildNode(folder1);
        tree.AddChildNode(folder10);
        tree.AddChildNode(folder20);

        pnlNamedUrl.Visible = true;

        return tree;
    }

    #endregion

    #region Create Tree Node using Name Url and Tag

    private UrlTreeNode CreateTreeNodesUsingNameURLAndTag()
    {
        UrlTreeNode tree = new UrlTreeNode("My Home", "Home", "Home");

        UrlTreeNode folder1 = new UrlTreeNode("My Folder1", "Folder1", "Folder1");
        UrlTreeNode folder2 = new UrlTreeNode("My Folder2", "Folder2", "Folder2");
        UrlTreeNode folder3 = new UrlTreeNode("My Folder3", "Folder3", "Folder3");
        UrlTreeNode folder4 = new UrlTreeNode("My Folder4", "Folder4", "Folder4");
        UrlTreeNode folder10 = new UrlTreeNode("My Folder10", "Folder10", "Folder10");
        UrlTreeNode folder11 = new UrlTreeNode("My Folder11", "Folder11", "Folder11");
        UrlTreeNode folder12 = new UrlTreeNode("My Folder12", "Folder12", "Folder12");
        UrlTreeNode folder20 = new UrlTreeNode("My Folder20", "Folder20", "Folder20");

        folder1.AddChildNode(folder2);
        folder1.AddChildNode(folder3);

        folder11.AddChildNode(folder1);

        folder10.AddChildNode(folder11);
        folder10.AddChildNode(folder12);
        folder10.AddChildNode(folder1);

        folder2.AddChildNode(folder10);

        folder4.AddChildNode(folder2);
        folder4.AddChildNode(folder3);

        folder11.AddChildNode(folder4);

        folder20.AddChildNode(folder4);
        folder20.AddChildNode(folder11);
        folder20.AddChildNode(folder12);

        folder4.AddChildNode(folder10);

        tree.AddChildNode(folder1);
        tree.AddChildNode(folder10);
        tree.AddChildNode(folder20);

        pnlTagUrl.Visible = true;

        return tree;
    }

    #endregion

    protected void btnAddressByNamedUrl_Click(object sender, EventArgs e)
    {
        //Home/Folder10/Folder11/Folder4
        if (!string.IsNullOrEmpty(txtAddress.Text))
        {
            VistaAddressBar1.SetAddressByNamedUrl(txtAddress.Text);
        }
    }

    protected void btnAddressByTagUrl_Click(object sender, EventArgs e)
    {
        //Home/Folder10/Folder11/Folder4
        if (!string.IsNullOrEmpty(txtTagAddress.Text))
        {
            VistaAddressBar1.SetAddressByTagUrl(txtTagAddress.Text);
        }
    }

    protected void VistaAddressBar1_NewLinkEvent(object sender, LinkButtonEventArgs e)
    {
        string msg = string.Format("NewLinkEvent Handled : Tree Node Name = <font style=\"FONT-WEIGHT: bold\">{0}</font>, Url = <font style=\"FONT-WEIGHT: bold\">{1}</font> and Tag = <font style=\"FONT-WEIGHT: bold\">{2}</font>",
            e.TreeNode.Name, e.TreeNode.Url, string.IsNullOrEmpty(e.TreeNode.Tag) ? "NULL" : e.TreeNode.Tag);
        lblText.Text = msg;
    }
}
